<?php
namespace Admin\Controller;

class SmsController extends CommonController{

	public function logs(){
		//状态
		$status = $this->_get('status');
		if($status){
			$where['status'] = $status;
		}
		$this->assign('status',$status);

		//类型
		$send_type = $this->_get('send_type');
		if($send_type){
			$where['send_type'] = $send_type;
		}
		$this->assign('send_type',$send_type);

		//按开始日期
		$start_date = $this->_get('start_date');
		if($start_date){
			$where['create_time'][] = array('egt',strtotime($start_date));
		}
		$this->assign('start_date',$start_date);

		//按结束日期
		$end_date   = $this->_get('end_date');
		if($end_date){
			$where['create_time'][] = array('elt',strtotime($end_date.'23:59:59'));
		}
		$this->assign('end_date',$end_date);

		$search_field = $this->_get('search_field');
		$keyword = $this->_get('keyword');
		if($keyword){
			$where[$search_field] = array('like', '%' . $$keyword . '%');
		}
		$this->assign('search_field', $search_field);
		$export = $this->_get('export');
		if($export){
			$this->_show_all_data = true;
		}
		$list  = parent::index('SmsSendLogs',$where,'id desc',true);
		$send_type_desc = array(
			'cl'            => '创蓝短信',
			'b2m'           => '亿美短信',
			'webchinese'    => '中国网建',
			'yunpian'       => '云片网短信',
			'yunpian_voice' => '云片网语音',
			'vcomcn'        => '集时通',
		);
		foreach ($list as $rs) {
			$rs['send_type_desc'] = $send_type_desc[$rs['send_type']];
			$rs['datetime'] = date('Y-m-d H:i:s', $rs['create_time']);
			$new_list[] = $rs;
		}
		//显示内容名称
		$data_title = array(
			'id'             => array('title'=>'编号','td_style'=>'','val_class'=>'','val_pre'=>'','val_default'=>''),
			'send_type_desc' => array('title'=>'类型','td_style'=>'','val_class'=>'','val_pre'=>'','val_default'=>''),
			'mobiles'        => array('title'=>'手机号','td_style'=>'','val_class'=>'','val_pre'=>'','val_default'=>''),
			'content'        => array('title'=>'内容','td_style'=>'width:380px;text-align:left','val_class'=>'','val_pre'=>'','val_default'=>''),
			'status'         => array('title'=>'状态码','td_style'=>'','val_class'=>'','val_pre'=>'','val_default'=>''),
			'result'         => array('title'=>'发送结果','td_style'=>'','val_class'=>'','val_pre'=>'','val_default'=>''),
			'datetime'       => array('title'=>'发送时间','td_style'=>'','val_class'=>'','val_pre'=>'','val_default'=>''),
		);
		if($export=='xls'){
			import("ExcelUtil",'Public/Class/suncco/');
			ExcelUtil::export($data_title, $new_list, '短信发送清单');
		}

		$this->assign('data_title', $data_title);
		$this->assign('list', $new_list);
		// $this->assign('table_width', '1200');
		$this->display();
	}
}